<?php

namespace app\admin\controller;

use app\BaseController;
use app\domain\admin\CommonDomain;
use app\service\RedisClusterService;
use think\response\Json;

class Common extends BaseController
{
    public string $message = 'success';

    public function __get($name)
    {
        return $this->$name ?? $this->request->$name ?? $this->request[$name] ?? request()->param($name) ?? null;
    }

    public function test()
    {
        //$redis = app(RedisClusterService::class)::run();
        //$redis->set('test', 'test', 10);

        $result = rabbitmqPush(json_encode(['name' => 'zhangsan', 'age' => 18], 320));
        print_r(get_class_methods($result));
    }

    public function getCaptcha(CommonDomain $domain): Json
    {
        try {
            $result = $domain->getCaptcha();

            return jsonReturn(0, $domain->message, $result);
        } catch (\Exception $e) {
            return jsonReturn(1, $e->getMessage());
        }
    }

    public function adminMenus(CommonDomain $domain): Json
    {
        try {
            $type = request()->param('type', 'all');
            $result = $domain->adminMenus($type);
            return jsonReturn(0, $domain->message, $result);
        } catch (\Exception $e) {
            return jsonReturn(1, $e->getMessage());
        }
    }

    public function adminGroup(CommonDomain $domain): Json
    {
        try {
            $result = $domain->adminGroup();
            return jsonReturn(0, $domain->message, $result);
        } catch (\Exception $e) {
            return jsonReturn(1, $e->getMessage());
        }
    }

    public function getPermCode(): Json
    {
        try {
            return jsonReturn(0, '', []);
        } catch (\Exception $e) {
            return jsonReturn(1, $e->getMessage());
        }
    }

    public function getMenuList(CommonDomain $domain): Json
    {
        try {
            $result = $domain->getMenuList();
            return jsonReturn(0, $domain->message, $result);
        } catch (\Exception $e) {
            return jsonReturn(1, $e->getMessage());
        }
    }
}